import collections
class Solution(object):
    def groupThePeople(self, groupSizes):
        c = collections.defaultdict(list)
        n = len(groupSizes)
        out = []
        for index, size in enumerate(groupSizes):
            c[size].append(index)
        for key in c:
            for i in range(len(c[key]) // key):
                temp = []
                for j in range(key):
                    temp.append(c[key][i * key + j])
                out.append(temp)
        return out

